﻿using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using System.Text;
using Galoap.JSON;
using Galoap;
using Galoap.Properties;
using Galoap.UnitTest.Storage;
using Galoap.Questions;
using Galoap.UnitTest;
using Galoap.Workflow;
using Galoap.Workflow.Model;
using Galoap.Workflow.ParseScxml;
using System.Collections.Generic;

public partial class tagImage : System.Web.UI.Page
{
    static bool postback = false;
    static Game g = null;
    static Question itq = null;
    static GameSession gs = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        /*
        if (!postback)
        {
            postback = true;
            try
            {
                // User u = Galoap.User.GetUserByNickname((string)Session["nick"]);
                User u = Galoap.User.GetUserByNickname("max");

                gs = GameSession.GetLastGameSessionByUser(u);
                gs.GameReference.Load();

                //Game ge = Game.GetGame(5);
                //GameSession gsession = u.GetLastGameSession();
                //GameSession s = Galoap.GameSession.GetLastGameSessionByUser(u);

                g = gs.Game;
                // Game g = Game.GetAllGames().OfType<ImageTagGame>().First(); // gs.Game;
                // GameSession gs = GameSession.GetLastGameSessionByGame(g);
                
            }
            catch (System.ArgumentException)
            {
                //non c'e l'utente
            }

        }


        string risposta = null;
        Hashtable lista = new Hashtable();

        string richiesta = Request.Params[0].ToString();
        try  {
            lista = (Hashtable)JSON.JsonDecode(richiesta);
        }
        catch (SystemException) { return; }
        try  {
            string type = (string)lista["event"];
            switch (type) {
                
                case "next": {
                        //itq = g.GetQuestion().First();
                        //risposta = Converter.toJSON(itq.Render()); // Converter.itq.Render();
                        risposta = "{\"txt\":\"Crea le giuste associazioni.\",\"interrogation\": \"qualcosa\",\"description\":\"Trascina la parola nel suo box.\",\"filejs\": \"URI.js\",\"filecss\": \"URI.css\",\"idocument\":\"images/Sunset.jpg\",\"questionid\": 35,\"knowledge\":\"casa|||pippo|||pippa\",\"info\":\"\",\"sessionid\": 536}";
                    }
                    break;
                case "gameResult": {

                    String risp = (string)lista["answer"];

                    StringAnswer ita = new StringAnswer();
                    ita.Data = risp;
                    // ita.Question = itq;

                    //Console.WriteLine("consensus: " + itq.BoolValidate(ita));
                    //Console.WriteLine("%: " + itq.Validate(ita));
                    int score = (int)(itq.Validate(ita)*100);

                    ((ImageTagQuestion)itq).UpdateAnswer(ita, gs);

                    risposta = "{\"point\":\""+score+"\"}";
                    }
                    break;
            }

        }
        catch (NullReferenceException) { return; }
        Response.Write(risposta);
        Response.End();*/

    }
}
